package com.example.demo.test;

/**
 * @author void
 * @date 2022/3/2 11:54
 * @desc 引用传递 VS 值传递
 */
public class ReferenceVsValue {

    public static void main(String[] args) {
        ReferenceVsValue obj = new ReferenceVsValue();
        
        //基本数据类型-值传递
        int a = 99;
        obj.test1(a);
        System.out.println(a);

        //基本数据类型-值传递
        Integer b = new Integer(200);
        obj.test2(b);
        System.out.println(b);
        
        //对象类型-引用传递
        ReferenceVsValue.MyObj c = new ReferenceVsValue.MyObj(100);
        obj.test3(c);
        System.out.println(c.param);
    }
    
    public void test1(int param){
        param++;
        System.out.println(param);
    }

    public void test2(Integer param){
        param++;
        System.out.println(param);
    }
    
    public void test3(MyObj myObj){
        myObj.param = myObj.param + 1;
        System.out.println(myObj.param);
    }
    
    static class MyObj{
        private Integer param;

        public MyObj(Integer param) {
            this.param = param;
        }

        public Integer getParam() {
            return param;
        }

        public void setParam(Integer param) {
            this.param = param;
        }
    }
}
